package kr.hkit.androidcomplete01.ch07;

import kr.hkit.androidcomplete01.R;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ComposeShader;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Shader.TileMode;
import android.os.Bundle;
import android.view.View;

public class MirrorImage extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		MyView vw = new MyView(this);
		setContentView(vw);
	}
	
	class MyView extends View{

		public MyView(Context context) {
			super(context);
		}
		
		public void onDraw(Canvas canvas){
			Paint pnt = new Paint();
			
			canvas.drawColor(Color.BLACK);
			
			Bitmap car = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.korandoc);
			
			int width = car.getWidth();
			int height = car.getHeight();
			
			Matrix matrix = new Matrix();
			matrix.preScale(1, -1f);
			Bitmap mirror = Bitmap.createBitmap(car, 0, 0, width, height, matrix, false);
			
			canvas.drawBitmap(car, 0, 0 ,null);
			ComposeShader comp = new ComposeShader(
					new BitmapShader(mirror, TileMode.REPEAT, TileMode.REPEAT),
					new LinearGradient(0, height, 0, height+height, Color.TRANSPARENT, Color.BLACK, TileMode.REPEAT),
					new PorterDuffXfermode(PorterDuff.Mode.DARKEN));
			pnt.setShader(comp);
			canvas.drawRect(0, height, width, height+height, pnt);
			
			
			
		}
	}
}
